/*
 * Copyright (C) 2018 guomw.Inc. All rights reserved.
 * 项目名称： report-manage
 * 文件名称： EnumJsonSerializer.java
 * Date：18-11-5 上午10:54
 * Author: guomw
 */

package com.guomw.report.common.enums;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author guomw
 * @date 2018/9/6
 */
public class EnumJsonSerializer implements Converter<ICommonEnum,Map> {
    @Override
    public Map convert(ICommonEnum value) {
        HashMap<String,Object> map = new HashMap();
        map.put("name",value.getName());
        map.put("value",value.getValue());
        return map;
    }

    @Override
    public JavaType getInputType(TypeFactory typeFactory) {
        return typeFactory.uncheckedSimpleType(ICommonEnum.class);
    }

    @Override
    public JavaType getOutputType(TypeFactory typeFactory) {
        return typeFactory.constructMapLikeType(Map.class,String.class,Object.class);
    }
}
